package com.test.quartz.memory.config;

import com.test.quartz.memory.job.Job1;
import org.quartz.*;
import org.springframework.context.annotation.Bean;

/**
 * 测试
 * 不用配置Scheduler, 只要导入spring-boot-starter-quartz, 系统就会自动给我们注入Scheduler到容器
 * 官网文档: If Quartz is available, a Scheduler is auto-configured (through the SchedulerFactoryBean abstraction)
 *
 * 硬编码任务配置
 */
//@Configuration
public class QuartConfig1 {

    @Bean
    public JobDetail jobDetail1(){
        JobDetail jodDetail = JobBuilder.newJob(Job1.class)
                .withIdentity("job1", "group1")
                .storeDurably()
                .build();
        return jodDetail;
    }

    @Bean
    public Trigger trigger1(){
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .forJob(jobDetail1())
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/3 * * * * ?"))
                .build();
        return trigger;
    }

}
